package com.www.dao;
import java.util.List;

import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.www.domain.BookOrder;

/**
 * 预定订单dao
 */
@Repository
public interface BookOrderDao {
	/*
	 * 预定订单插入操作
	 */
	@Insert("insert into book_order(id,accountId,roomTypeId,name,idCard,mobile,status,arriveDate,leaveDate,createTime,remark) values(default,#{accountId},#{roomTypeId},#{name},#{idCard},#{mobile},#{status},#{arriveDate},#{leaveDate},#{createTime},#{remark})")
	public int add(BookOrder bookOrder);
	
	/*
	 * 预定订单编辑操作
	 */
	@Insert("update book_order set accountId = #{accountId},roomTypeId = #{roomTypeId},name = #{name},arriveDate = #{arriveDate},leaveDate = #{leaveDate},idCard = #{idCard},mobile = #{mobile},status = #{status},remark = #{remark} where id = #{id}")
	public int edit(BookOrder bookOrder);
	
	/*
	 * 删除预定订单信息
	 */
	@Delete("delete from book_order where id = ${value}")
	public int delete(Long id);
	
	/*
	 * 预定订单信息搜索查询
	 */
	@Select({"<script> "+
			"select * from book_order " +
			"where  1=1 " +
			"<if test='name != null'> and name like '%${name}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
			"<if test='accountId != null'> and accountId like '%${accountId}%'</if>" +
			"<if test='roomTypeId != null'> and roomTypeId like '%${roomTypeId}%'</if>" +
			"<if test='idCard != null'> and idCard like '%${idCard}%'</if>" +
			"<if test='mobile != null'> and mobile like '%${mobile}%'</if>" +
			"<if test='offset != null and pageSize != null'> limit #{offset},#{pageSize}</if>" +
	 		"</script>"})
	public List<BookOrder> findList(Map<String, Object> queryMap);
	
	/*
	 * 模糊搜索总条数 
	 */
	@Select({"<script> "+
			"select count(*) from book_order " +
			"where 1=1 " +
			"<if test='name != null'> and name like '%${name}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
			"<if test='accountId != null'> and accountId like '%${accountId}%'</if>" +
			"<if test='roomTypeId != null'> and roomTypeId like '%${roomTypeId}%'</if>" +
			"<if test='idCard != null'> and idCard like '%${idCard}%'</if>" +
			"<if test='mobile != null'> and mobile like '%${mobile}%'</if>" +
	 		"</script>"})
	public Integer getTotal(Map<String, Object> queryMap);
	
	/*
	 * 获取单个预定订单信息
	 */
	@Select("select * from book_order where id = #{value}")
	public BookOrder find(Long id);
}
